<% include ../header.ejs %>

<link rel="stylesheet" href="/lib/datetimepicker/css/amazeui.datetimepicker.css"/>

<script src="/lib/datetimepicker/js/amazeui.datetimepicker.min.js"></script>
<script src="/lib/datetimepicker/js/locales/amazeui.datetimepicker.zh-CN.js"></script>

<header data-am-widget="header" data-am-sticky class="am-header am-header-default" id="appTemplates-Nav">
    <div class="am-header-left am-header-nav">
        <a href='javascript:history.go(-1)' class="">
            <img class="am-header-icon-custom" src="data:image/svg+xml;charset&#x3D;utf-8,&lt;svg xmlns&#x3D;&quot;http://www.w3.org/2000/svg&quot; viewBox&#x3D;&quot;0 0 12 20&quot;&gt;&lt;path d&#x3D;&quot;M10,0l2,2l-8,8l8,8l-2,2L0,10L10,0z&quot; fill&#x3D;&quot;%23fff&quot;/&gt;&lt;/svg&gt;" alt=""/>
        </a>
    </div>

    <h1 class="am-header-title">
        <a href="#title-link" class="" id="Typeface-whitecolor">新建路演</a>
    </h1>

    <div class="am-header-right am-header-nav">
        <a onclick="javascript:$('#save').click();" class="" data-am-modal="{target: '#modal-type-add', closeViaDimmer: 0, width: 240, height: 260}">保存</a>
    </div>
</header>

<form name="editroadshow" class="am-form" method="post" action="edit" data-am-validator>
    <fieldset>
        <input type="hidden" name="rowId" value="<%=info.obj.rowId%>"/>
        <div class="am-form-group" style="margin-top:5px;">
            <label for="doc-vld-name">开始时间:</label>
            <div class="am-input-group date" id="start_datetime" data-date-format="yyyy-mm-dd hh:ii">
                <input name="startTime" id="startTime" type="text" placeholder="开始时间" class="am-form-field"  value="<%=moment(info.obj.startTime).format('YYYY-MM-DD hh:mm')%>" readonly required>
                <span class="am-input-group-label add-on"><i class="icon-th am-icon-calendar"></i></span>
            </div>
        </div>

        <div class="am-form-group" style="margin-top:5px;">
            <label for="doc-vld-name">结束时间:</label>
            <div class="am-input-group date" id="end_datetime" id="end_datetime" data-date-format="yyyy-mm-dd hh:ii">
                <input name="finishTime" type="text" placeholder="结束时间" class="am-form-field" value="<%=moment(info.obj.finishTime).format('YYYY-MM-DD hh:mm')%>" readonly required>
                <span class="am-input-group-label add-on"><i class="icon-th am-icon-calendar"></i></span>
            </div>
        </div>

        <div class="am-form-group" style="margin-top:5px;">
            <label for="doc-vld-name">券商:</label>
            <select name="seller" data-am-selected="{btnWidth:'100%'}" placeholder="选择券商" required>
                <% seller.obj.forEach(function (data, index) {%>
                <option value="<%=data.rowId%>" <%if(data.rowId==info.obj.seller.rowId){%>selected<%}%>><%=data.name%></option>
                <% })%>
            </select>
        </div>

        <div class="am-form-group" style="margin-top:5px;">
            <label for="doc-vld-name">行业:</label>
            <select name="industry" data-am-selected="{btnWidth:'100%'}" placeholder="选择行业" required>
                <% industry.obj.forEach(function (data, index) {%>
                <option value="<%=data.rowId%>" <%if(data.rowId==info.obj.industry.rowId){%>selected<%}%>><%=data.industryName%></option>
                <% })%>
            </select>
        </div>

        <!--<div class="am-form-group" style="margin-top:5px;">-->
            <!--<label for="doc-vld-name">会议地点:</label>-->
            <!--<select name="meetingroom" data-am-selected="{btnWidth:'100%'}" placeholder="选择会议地点">-->
                <!--<% meetingroom.obj.forEach(function (data, index) {%>-->
                    <!--<option value="<%=data.rowId%>" <%if(data.rowId==info.obj.address.rowId){%>selected<%}%>><%=data.address%></option>-->
                <!--<% })%>-->
            <!--</select>-->
        <!--</div>-->


        <div style="margin-top:5px;">
            <label for="doc-vld-name">路演类型:</label>
            <div style="width:244px;">
                <div id="schedule_type_switch" class="am-btn-group" data-am-button>
                    <label class="am-btn am-btn-secondary">
                        <input type="radio" name="roadshow_type" value="分析师" <%if(info.obj.type=='分析师'){%>checked<%}%> needsclick>分析师</input>
                    </label>
                    <label class="am-btn am-btn-secondary">
                        <input type="radio" name="roadshow_type" value="上市公司" <%if(info.obj.type=='上市公司'){%>checked<%}%> needsclick>上市公司</input>
                    </label>
                    <label class="am-btn am-btn-secondary">
                        <input type="radio" name="roadshow_type" value="专家" <%if(info.obj.type=='专家'){%>checked<%}%> needsclick>专家</input>
                    </label>
                    <input type="hidden" id="type" name="type" value="<%=info.obj.type%>"/>
                </div>
            </div>
        </div>

        <!-- 分析-->
        <div id="analyst_container"  <%if(info.obj.type!='分析师'){%>style="display: none; margin-top: 5px;"<%} else {%>style="margin-top: 5px;"<%}%>>
            <div>
                <label for="doc-vld-name">类型:</label>
                <div style="width:259px;">
                    <div id="schedule_type_switch" class="am-btn-group" data-am-button>
                        <label class="am-btn am-btn-secondary">
                            <input type="radio" name="roadshow_recommend" value="行业深度推荐" <%if(info.obj.recommend=='行业深度推荐'){%>checked<%}%> needsclick>行业深度推荐</input>
                        </label>
                        <label class="am-btn am-btn-secondary">
                            <input type="radio" name="roadshow_recommend" value="公司深度推荐" <%if(info.obj.recommend=='公司深度推荐'){%>checked<%}%> needsclick>公司深度推荐</input>
                        </label>
                        <input type="hidden" id="recommend" name="recommend" value="<%=info.obj.recommend%>"/>
                    </div>
                </div>
            </div>

            <div id="group_containers" <%if(info.obj.type=='分析师'&&info.obj.recommend=='公司深度推荐'){%>style="margin-top: 5px;"<%} else {%>style="margin-top: 5px;display: none; "<%}%>>
                <div class="am-form-group" style="margin-top:5px;height:37px;" id="group_container_1">
                    <div class="am-u-sm-6" style="padding-left: 0rem;padding-right: 0rem">
                        <select id="company_name_analyst_1" class="company-data-ajax" style="width: 100%" placeholder="选择股票">
                        </select>
                    </div>
                    <div class="am-u-sm-2" style="padding-left: 0rem;padding-right: 0rem">
                        <select id="operate_analyst_1" data-am-selected="{btnWidth:'100%'}" placeholder="选择">
                            <option value="买入" selected>买入</option>
                            <option value="持有" >持有</option>
                            <option value="卖出" >卖出</option>
                        </select>
                    </div>
                    <div class="am-u-sm-2 am-u-end" style="padding-left: 1rem;padding-right: 0rem">
                        <button type="button" class="am-btn am-icon-plus am-btn-primary" id="plus_1"></button>
                    </div>
                </div>

                <div class="am-form-group" style="display:none;margin-top:5px;height:37px;" id="group_container_2">
                    <div class="am-u-sm-6" style="padding-left: 0rem;padding-right: 0rem">
                        <select id="company_name_analyst_2" class="company-data-ajax" style="width: 100%" placeholder="选择股票">
                        </select>
                    </div>
                    <div class="am-u-sm-2" style="padding-left: 0rem;padding-right: 0rem">
                        <select id="operate_analyst_2" data-am-selected="{btnWidth:'100%'}" placeholder="选择">
                            <option value="买入" selected>买入</option>
                            <option value="持有" >持有</option>
                            <option value="卖出" >卖出</option>
                        </select>
                    </div>
                    <div class="am-u-sm-2" style="padding-left: 1rem;padding-right: 0rem">
                        <button type="button" class="am-btn am-icon-plus am-btn-primary" id="plus_2"></button>
                    </div>
                    <div class="am-u-sm-2 am-u-end" style="padding-left:1rem;padding-right: 0rem">
                        <button type="button" class="am-btn am-icon-minus am-btn-danger" id="minus_1"></button>
                    </div>
                </div>

                <div class="am-form-group" style="display:none;margin-top:5px;height:37px;" id="group_container_3">
                    <div class="am-u-sm-6" style="padding-left: 0rem;padding-right: 0rem">
                        <select id="company_name_analyst_3" class="company-data-ajax" style="width: 100%" placeholder="选择股票">
                        </select>
                    </div>
                    <div class="am-u-sm-2" style="padding-left: 0rem;padding-right: 0rem">
                        <select id="operate_analyst_3" data-am-selected="{btnWidth:'100%'}" placeholder="选择">
                            <option value="买入" selected>买入</option>
                            <option value="持有" >持有</option>
                            <option value="卖出" >卖出</option>
                        </select>
                    </div>
                    <div class="am-u-sm-2 am-u-end" style="padding-left:1rem;padding-right: 0rem">
                        <button type="button" class="am-btn am-icon-minus am-btn-danger" id="minus_2"></button>
                    </div>
                </div>
            </div>

            <div  style="margin-top: 5px;">
                <label for="doc-vld-name">分析师:</label>
                <select multiple data-am-selected="{btnWidth: '100%'}" placeholder="请选择分析师" id="name_analyst" name="name_analyst">
                    <% person.obj.forEach(function (data, index) {%>
                    <option value="<%=data.rowId%>"  <% info.obj.userjoinList.forEach(function (data_userinfo, index) {%><%if(data.rowId==data_userinfo.userId.rowId&&data_userinfo.userType=="analyst"){%>selected<%}%><% })%> ><%=data.name%></option>
                    <% })%>
                </select>
            </div>

            <div style=" margin-top: 5px;">
                <label for="doc-vld-name">预约人:</label>
                <select multiple data-am-selected="{btnWidth: '100%'}" placeholder="请选择预约者" id="person_name_analyst" name="person_name_analyst">
                    <% person.obj.forEach(function (data, index) {%>
                        <option value="<%=data.rowId%>"  <% info.obj.userjoinList.forEach(function (data_userinfo, index) {%><%if(data.rowId==data_userinfo.userId.rowId&&data_userinfo.userType=="participant"){%>selected<%}%><% })%> ><%=data.name%></option>
                    <% })%>
                </select>
            </div>

            <div style=" margin-top: 5px;">
                <label for="doc-vld-name">核心观点:</label>
                <textarea class="" rows="8" id="content_analyst" name="content_analyst" placeholder="核心观点"><%if(info.obj.type=='分析师'){%><%=info.obj.content%><%}%></textarea>
            </div>
        </div>

        <!-- 上市公司-->
        <div id="company_container" class="am-form-group" <%if(info.obj.type!='上市公司'){%>style="display: none; margin-top: 5px;"<%} else {%>style="margin-top: 5px;"<%}%>>
            <div class="am-form-group" style="margin-top:5px;margin-bottom: 0rem;">
                <input id="visit_company" type="text" placeholder="请输入来访人" value="<%=info.obj.guestCompany%>"></input>
            </div>

            <!-- TODO 公司赋值-->
            <div class="am-form-group" style="margin-top: 5px;">
                <select class="company-data-ajax" style="width: 100%" id="company_name_company">
                    
                </select>
            </div>

            <div  class="am-form-group" style="margin-top: 5px;">
                <select multiple data-am-selected="{btnWidth: '100%'}" placeholder="请选择预约人" id="person_name_company">
                    <% person.obj.forEach(function (data, index) {%>
                    <option value="<%=data.rowId%>"  <% info.obj.userjoinList.forEach(function (data_userinfo, index) {%><%if(data.rowId==data_userinfo.userId.rowId){%>selected<%}%><% })%> ><%=data.name%></option>
                    <% })%>
                </select>
            </div>

            <div  style="margin-top:5px;">
                <label for="doc-vld-name">沟通类型:</label>
                <div style="width:334px;">
                    <div id="schedule_type_switch" class="am-btn-group" data-am-button>
                        <label class="am-btn am-btn-secondary">
                            <input type="radio" name="money_type" value="定期沟通" <%if(info.obj.subtypeCompany=='定期沟通'){%>checked<%}%> needsclick>定期沟通</input>
                        </label>
                        <label class="am-btn am-btn-secondary">
                            <input type="radio" name="money_type" value="IPO或增发事项" <%if(info.obj.subtypeCompany=='IPO或增发事项'){%>checked<%}%> needsclick>IPO或增发事项</input>
                        </label>
                        <label class="am-btn am-btn-secondary">
                            <input type="radio" name="money_type" value="融券融资" <%if(info.obj.subtypeCompany=='融券融资'){%>checked<%}%> needsclick>融券融资</input>
                        </label>
                        <input type="hidden" id="type_money_company" value="定期沟通"  value="<%=info.obj.subtypeCompany%>"/>
                    </div>
                </div>
            </div>
        </div>

        <!-- 专家-->
        <div id="expert_container" class="am-form-group" <%if(info.obj.type!='专家'){%>style="display: none; margin-top: 5px;"<%} else {%>style="margin-top: 5px;"<%}%>>
            <div style="margin-top:5px;margin-bottom: 0rem;">
                <label for="doc-vld-name">专家领域:</label>
                <input id="expert_name_expert" type="text" placeholder="请输入专家领域" value="<%=info.obj.fieldPro%>"></input>
            </div>

            <div style="margin-top:5px;margin-bottom: 0rem;">
                <label for="doc-vld-name">来访人:</label>
                <input id="visit_expert" type="text" placeholder="请输入来访人" value="<%=info.obj.guestPro%>"></input>
            </div>

            <div style="margin-top: 5px;">
                <label for="doc-vld-name">预约人:</label>
                <select multiple data-am-selected="{btnWidth: '100%'}" placeholder="请选择预约人" id="person_name_expert">
                    <% person.obj.forEach(function (data, index) {%>
                    <option value="<%=data.rowId%>"  <% info.obj.userjoinList.forEach(function (data_userinfo, index) {%><%if(data.rowId==data_userinfo.userId.rowId){%>selected<%}%><% })%> ><%=data.name%></option>
                    <% })%>
                </select>
            </div>

            <div style=" margin-top: 5px;">
                <label for="doc-vld-name">来访目的:</label>
                <textarea class="" rows="8" id="content_expert" placeholder="请输入来访目的"><%if(info.obj.type=='专家'){%><%=info.obj.content%><%}%></textarea>
            </div>
        </div>

        <button class="am-btn am-btn-secondary" type="submit" id="save" style="visibility:hidden">提交</button>

    </fieldset>
</form>

<form name="delroadshow" id="delroadshow" class="am-form" method="post" action="delete">
    <fieldset>
        <input type="hidden" name="rowId" value="<%=info.obj.rowId%>"/>
        <button id="btnDelRoadshow" type="button" class="am-btn am-btn-danger am-btn-block">删除</button>
    </fieldset>

    <div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
        <div class="am-modal-dialog">
            <div class="am-modal-hd">删除日程</div>
            <div class="am-modal-bd">
                确定要删除这条记录吗？
            </div>
            <div class="am-modal-footer">
                <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                <span class="am-modal-btn" data-am-modal-confirm>确定</span>
            </div>
        </div>
    </div>
</form>

<script src="/javascripts/app/schedule/roadshow_edit.js"></script>

<script type="text/javascript">
    $(document).ready(function() {


        if("<%=info.obj.type%>"=="分析师") {
            $('#recommend').attr("name",'recommend');
            $('#name_analyst').attr("name",'name_analyst');
            $('#person_name_analyst').attr("name",'person_name_analyst');
            $('#content_analyst').attr("name",'content_analyst');

            $('#visit_company').removeAttr("name");
            $('#company_name_company').removeAttr("name");
            $('#person_name_company').removeAttr("name");
            $('#type_money_company').removeAttr("name");

            $('#expert_name_expert').removeAttr("name");
            $('#visit_expert').removeAttr("name");
            $('#person_name_expert').removeAttr("name");
            $('#content_expert').removeAttr("name");
        }else  if("<%=info.obj.type%>"=="上市公司"){
            $('#recommend').removeAttr("name");
            $('#name_analyst').removeAttr("name");
            $('#person_name_analyst').removeAttr("name");
            $('#content_analyst').removeAttr("name");

            $('#visit_company').attr("name",'visit_company');
            $('#company_name_company').attr("name",'company_name_company');
            $('#person_name_company').attr("name",'person_name_company');
            $('#type_money_company').attr("name",'type_money_company');

            $('#expert_name_expert').removeAttr("name");
            $('#visit_expert').removeAttr("name");
            $('#person_name_expert').removeAttr("name");
            $('#content_expert').removeAttr("name");
        }else {
            $('#recommend').removeAttr("name");
            $('#name_analyst').removeAttr("name");
            $('#person_name_analyst').removeAttr("name");
            $('#content_analyst').removeAttr("name");

            $('#visit_company').removeAttr("name");
            $('#company_name_company').removeAttr("name");
            $('#person_name_company').removeAttr("name");
            $('#type_money_company').removeAttr("name");

            $('#expert_name_expert').attr("name",'expert_name_expert');
            $('#visit_expert').attr("name",'visit_expert');
            $('#person_name_expert').attr("name",'person_name_expert');
            $('#content_expert').attr("name",'content_expert');
        }

        if("<%=info.obj.recommend%>"=="公司深度推荐") {
            $('#company_name_analyst_1').attr("name",'company_name_analyst_1');
            $('#operate_analyst_1').attr("name",'operate_analyst_1');
        }else {
            $('#company_name_analyst_1').removeAttr("name");
            $('#operate_analyst_1').removeAttr("name");

            $('#company_name_analyst_2').removeAttr("name");
            $('#operate_analyst_2').removeAttr("name");

            $('#company_name_analyst_3').removeAttr("name");
            $('#operate_analyst_3').removeAttr("name");
        }

//        var $type = $('[name="roadshow_type"]');
//        $type.change()
    });

    $(".company-data-ajax").select2({
        ajax: {
            url: "../../../api/dicStock/getStockList",
            dataType: 'json',
            delay: 250,
            data: function (params) {
                return {
                    name: params.term
                };
            },
            processResults: function (data, params) {
                params.page = params.page || 1;
                var newdata = $.map(data.obj, function (obj) {
                    obj.id = obj.id || obj.rowId; // replace pk with your identifier
                    obj.text = obj.text ||obj.stockCode+" "+ obj.name;
                    return obj;
                });

                return {
                    results: newdata,
                    pagination: {
                        more: (params.page * 30) < data.total_count
                    }
                };
            },
            cache: true
        },
        escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
        minimumInputLength: 2
    });

    //++++++++++++++++限制开始时间大于当前,结束时间大于开始时间
    $(function() {

        $('#start_datetime').datetimepicker('setStartDate', new Date());
        $('#end_datetime').datetimepicker('setStartDate',new Date());

        $("#startTime").on("change",function(event){
            var strTime=$("#startTime").val();
//            var date=new Date(Date.parse(strTime));
            var date = new Date(Date.parse(strTime.replace(/-/g, "/")));
            var endTime=new Date(date.setHours(date.getHours()+1));
            var strEndTime=dateToStr(endTime);
            $("#finishTime").val(strEndTime);



            $('#end_datetime').datetimepicker('setStartDate',strEndTime);
        });

    });

    function dateToStr(date){
        var dd = date.getDate() < 10 ? "0" + date.getDate() : date.getDate().toString();
        var month=date.getMonth()+1;
        var mmm = month<10? "0" +month: month.toString()
        var yyyy = date.getFullYear().toString();
        var hour=date.getHours()<10 ? "0"+date.getHours():date.getHours().toString();
        var min=date.getMinutes()<10?"0"+date.getMinutes():date.getMinutes().toString();
        return yyyy+"-"+mmm+"-"+dd+" "+hour+":"+min;
    }

</script>


<% include ../footer.ejs %>
